from datetime import datetime
from .lpnode import LPNode, LPNodeType


class LPBegin(LPNode):
    """
    begin node in pipeline.
    """

    def __init__(self, name) -> None:
        super().__init__(name, LPNodeType.Begin, None)
    
    def input(self, query, query_images=None, sync=True):
        """
        construct lpdata and call super().run(), start to run the pipeline.

        **parameters**
        - query(str): input text or prompt.
        - query_images([]): input images with cv2.mat format, None by default.
        - sync(bool): start pipeline with sync or aysnc mode.
        """ 
        
        # construct lpdata which will flowing the piepline
        lpdata = {}
        # running mode
        lpdata['sync'] = sync
        # begin time
        lpdata['begin_t'] = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        # end time
        lpdata['end_t'] = None
        # input text or prompt
        lpdata['query'] = query
        # input images
        lpdata['query_imgs'] = query_images
        # final output generated by pipeline
        lpdata['final_out'] = None
        # global variables when lpdata flowing the pipeline
        lpdata['global_vars'] = {}
        # handle records when lpdata flowing the pipeline
        lpdata['records'] = []

        super().run(lpdata)


